package com.fwzhang.eurekaclient.bean;

import com.fwzhang.eurekaclient.service.SelfInitializingService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;

@Service()
public class SelfInitializingBean implements ApplicationContextAware, BeanPostProcessor, InitializingBean {

    private static final Logger logger = LoggerFactory.getLogger(SelfInitializingBean.class);

    private static int index = 0;

    private ApplicationContext applicationContext;

    @Autowired
    private SelfInitializingService selfInitializingService;

    public SelfInitializingBean() {
        logger.info("构造函数开始执行");
    }

    @PostConstruct
    private void init() {
        logger.info(" postConstruct方法开始执行");
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        logger.info("initializingBean方法开始执行");
    }

    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        logger.info("beanPostProcessor前置方法开始执行");
        return null;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        logger.info("beanPostProcessor后置方法开始执行");
        return null;
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        logger.info("aware  开始执行");
        this.applicationContext = applicationContext;
    }
}
